package com.soft.controller;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.soft.entity.Money;
import com.soft.service.MoneyService;

@RestController
public class MoneyController {
@Autowired
private MoneyService moneyService;
@RequestMapping("/queryAllMoney")
public List<Money> queryAll(){
	return moneyService.queryAll();
}
@RequestMapping("/queryByIncome")
public List<Money> queryByIncome(BigDecimal incomecount){
	return moneyService.queryByIncome(incomecount);
}
@RequestMapping("/queryAddMoney")
public String queryAddMoney(BigDecimal income,BigDecimal spend ,BigDecimal total,BigDecimal opid) {
    Money money = new Money();
    money.setIncome(income);
    money.setSpend(spend);
    money.setTotal(total); 
    money.setOperatorid(opid);
    int num = moneyService.addMoney(money);
    return num == 1 ? "加入成功" : "加入失败";
}
@RequestMapping("/queryDeleteById")
public String queryDeleteById( long id){
	int result = moneyService.deleteMoneyById(id);
	return result > 0 ? "success" : "fail";
}
@RequestMapping("/queryUpdateById")
public String queryUpdateById( long id,BigDecimal income,BigDecimal spend ,BigDecimal total,BigDecimal opid){
	Money money = new Money();
	money.setId(id);
    money.setSpend(new BigDecimal("200"));
    money.setTotal(new BigDecimal("400"));
    money.setOperatorid(opid);
    int result = moneyService.updateMoneyById(money);
	return result == 1 ? "更新成功" : "更新失败";
}
}

